//
//  TongJiViewController.m
//  植物管理
//
//  Created by liujianlong on 2022/11/21.
//

#import "TongJiViewController.h"
#import "TongJiCell.h"

@interface TongJiViewController ()
@property (strong, nonatomic) IBOutlet UIButton *dateBtn;
@property (nonatomic,  assign) NSInteger stamp;
@property (nonatomic, strong) UIButton *timeBtn;

@end

@implementation TongJiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}
- (void)initUI{
    self.timeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.timeBtn.tag = 303;
    self.timeBtn.frame = CGRectMake(0, 0, 90, 30);
    [self.timeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [ self.timeBtn addTarget:self action:@selector(actionForBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"下拉"]];
    img.frame = CGRectMake(self.timeBtn.frame.size.width, 5, 14, 16);
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, StuBarHight + 5, 110, 30)];
    [view addSubview:self.timeBtn];
    [view addSubview:img];
    self.navigationItem.titleView = view;
    self.stamp = [[NSDate currentTimeStamp:@"yyyy/MM/dd HH:mm:ss"] intValue];
    self.tableView.c_top.equalTo(self.dateBtn.c_bottom).coffset(10);
    self.tableView.c_left.equalTo(self.view).coffset(20);
    self.tableView.c_right.equalTo(self.view).coffset(-20);
    self.tableView.c_bottom.equalTo(self.view).coffset(-20);
    [self.tableView registerNib:[TongJiCell nib] forCellReuseIdentifier:[TongJiCell ID]];
}
- (void)actionForBtn:(UIButton*)sender{
    WS(self)
    JZBDateViewController *vc = [JZBDateViewController new];
    vc.stamp = [[NSDate currentTimeStamp:@"yyyy/MM/dd HH:mm:ss"] intValue];
    vc.selectBlock = ^(int stamp) {
        weakself.stamp = stamp;
    };
    [self presentViewController:vc animated:NO completion:nil];
}

- (void)setStamp:(NSInteger)stamp{
    _stamp = stamp;
    NSString *title = [NSDate transToDate:LS(@"yyyy.MM") :stamp];
    [self.timeBtn setTitle:title forState:UIControlStateNormal];
    NSString *title2 = [NSDate transToDate:LS(@"MM月/yyyy") :stamp];
    [self.dateBtn setTitle:title2 forState:UIControlStateNormal];
    [self.tableView reloadData];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TongJiCell *cell = [tableView dequeueReusableCellWithIdentifier:[TongJiCell ID]];
    cell.stamp = self.stamp;
    return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return  0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return  nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
}
@end
